package com.hs.srm.admin.modules.summary.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hs.srm.admin.modules.orders.dao.ScmPoItemDao;
import com.hs.srm.admin.modules.summary.dao.VendorSummaryDao;
import com.hs.srm.admin.modules.summary.entity.VendorSummaryEntity;
import com.hs.srm.admin.modules.summary.service.VendorSummaryService;
import com.hs.srm.base.common.config.SysConfig;
import com.hs.srm.base.common.utils.QueryParam;
import com.hs.srm.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sunnykid.character.UtilCharacter;
import sunnykid.file.DirectoryOperator;
import sunnykid.file.FileOperator;
import sunnykid.file.office.OfficeFileOperator;
import sunnykid.file.office.OperatorFactory;
import sunnykid.text.SunnykidText;

import java.io.File;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Service
public class VendorVendorSummaryServiceImpl extends ServiceImpl<VendorSummaryDao, VendorSummaryEntity> implements VendorSummaryService {
    @Autowired
    private VendorSummaryDao vendorSummaryDao;
    @Autowired
    private ScmPoItemDao scmPoItemDao;

    @Override
    public PageUtils selectDetailPage(Map<String, Object> params) {
        Page<VendorSummaryEntity> page = this.selectDetailPage(new QueryParam<VendorSummaryEntity>(params).getPage(),
                new EntityWrapper<VendorSummaryEntity>(), params);
        return new PageUtils(page);
    }

    /**
     * 总价值总和
     *
     * @return
     */
    @Override
    public BigDecimal selectAllTatolPrice() {
        return this.scmPoItemDao.selectAllPrice();
    }

    /**
     * 总数量总和
     *
     * @return
     */
    @Override
    public BigDecimal selectAllpoCounts() {
        return this.vendorSummaryDao.selectAllpoCounts();
    }




    @Override
    public List<VendorSummaryEntity> selectByConditions(String[] vendorIds) {
        return this.vendorSummaryDao.selectByConditions(vendorIds);
    }

    private Page<VendorSummaryEntity> selectDetailPage(Page<VendorSummaryEntity> page, Wrapper<VendorSummaryEntity> wrapper,
                                                       Map<String, Object> params) {
        String conditions = (String) params.get("conditions");
        if (conditions.equals("ordertotalPrice")) {
            page.setRecords(this.vendorSummaryDao.selectByPrice(page, wrapper, params));
        } else {
            page.setRecords(this.vendorSummaryDao.selectByOrders(page, wrapper, params));
        }
        return page;
    }
}